{include file="public/layout" /}
<style>
    .icon-link_add {
        background-color: #fff;
        position: absolute;
        top: 5px;
        right: 6px;
        text-align: center;
        border: 1px solid #e1e1e1;
        border-radius: 50%;
        cursor: pointer;
    }
    .iconfont {
        font-family: "iconfont" !important;
        font-size: 16px;
        font-style: normal;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    .e-jiahao2 {
        color: #adadad;
        font-weight: 700;
    }
    .e-jianhao {
        color: #3fa9e0;
        font-weight: 700;
    }
</style>
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-10">
    <div class="row-bar clearfix mb10">
        {include file="weapp/bar" /}
        <div class="flexigrid fr">
            <form class="navbar-form form-inline" action="{:url('Weapp/index')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="ftitle">
                    <div class="sDiv2 fl" style="">
                        <input type="text" size="30" name="keywords" class="qsbox" placeholder="搜索应用名称..." autocomplete="off">
                        <input type="submit" class="btn" value="搜索">
            			<i class="iconfont e-sousuo"></i>
                    </div>
                </div>
            </form>
        </div>
    </div>
    
    <div class="flexigrid">
        <div class="plug-list">
            {empty name="list"}
            <div class="bDiv" style="height: auto;">
                <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                    <table style="width: 100%">
                        <tbody>
                            <tr>
                                <td class="no-data" align="center" axis="col0" colspan="50">
                                    <div class="no_row">
                                        <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="iDiv" style="display: none;"></div>
            </div>
            {else /}
                <script>
                    var update_admin_menu_url = "{:url('Ajax/update_admin_menu', ['_ajax'=>1])}";   //添加、删除入口地址
                    var is_founder = {$is_founder|default=0};
                    $(function(){
                        //添加、取消成为栏目
                        $(".bodystyle").on('click','.e-jiahao2',function (){
                            if(is_founder !== 1){
                                return false;
                            }
                            var menu_id = $(this).data('menu_id');
                            var title = $(this).data('name');
                            var controller_name = "Weapp" ;
                            var action_name = "execute" ;
                            var param = $(this).data('param');
                            var target = $(this).data('target');
                            var icon = "iconfont e-chajian" ;
                            _this = this;
                            if($(this).hasClass('e-jianhao')) {  //原本为“已添加”，去除"我的菜单"，修改下面块为“未添加”模式，且显示
                                $.ajax({
                                    type: "POST",
                                    url: update_admin_menu_url,
                                    data: {title:title,controller_name:controller_name,action_name:action_name,menu_id:menu_id,icon:icon,param:param,target:target,type:2},
                                    dataType: 'json',
                                    success:function (res) {
                                        if(res.code == 1){
                                            //修改状态
                                            $(_this).removeClass('e-jianhao');
                                            //去除左侧菜单
                                            parent.$("."+controller_name+'_'+action_name+'_'+menu_id).remove();
                                        }
                                        return false;
                                    }
                                });
                            }else{          //原本为未添加，添加到我的菜单
                                $.ajax({
                                    type: "POST",
                                    url: update_admin_menu_url,
                                    data: {title:title,controller_name:controller_name,action_name:action_name,menu_id:menu_id,icon:icon,param:param,target:target,type:1,is_switch:0},
                                    dataType: 'json',
                                    success:function (res) {
                                        if(res.code == 1){
                                            //修改状态
                                            $(_this).addClass('e-jianhao');
                                            //添加左侧菜单
                                            var html = '<a data-child="0"  data-id="'+menu_id+ '" class="left_menu_'+menu_id+ ' '+controller_name+'_'+action_name+'_'+menu_id+'" id="'+controller_name+'_'+action_name+'"  data-menu_id="' + menu_id + '" href="javascript:void(0);" data-param="'+controller_name+'|'+action_name+param+'" data-target="'+target+'" >'
                                                +'<i class="'+icon+'"></i>'+title+'</a>';
                                            if (parent.$(".left_menu_2004")){
                                                parent.$(".left_menu_2004").before(html);
                                            }else{
                                                parent.$("#sub-menu").append(html);
                                            }
                                        }
                                        return false;
                                    }
                                });
                            }
                        });
                    });
                </script>
                {foreach name="list" item="vo" key="k" }
                <div class="plug-item-content">
                    <div class="plug-item-top">
                        <div class="plug-img">
                            <a href="{:url('Weapp/execute',array('sm'=>$vo['code'],'sc'=>$vo['code'],'sa'=>'index'))}" {if condition="!empty($vo['config']['management']['href'])"} target="{$vo['config']['management']['target']|default='_self'}" {/if}><img src="{$vo.config.litpic|get_default_pic=###}?v={$vo.config.version}" ></a>
                        </div>
                        <div class="plug-text">
                            <div class="plug-text-title">
                                <a class="title-l" href="{:url('Weapp/execute',array('sm'=>$vo['code'],'sc'=>$vo['code'],'sa'=>'index'))}" {if condition="!empty($vo['config']['management']['href'])"} target="{$vo['config']['management']['target']|default='_self'}" {/if}>{$vo.name}</a>
                                {$RenewList[$vo['code']]['maturity_text']|default=''}
                                {notempty name="$is_founder"}
                                    {if condition="!empty($vo.config.management.href)"}
                                        <div class="icon-link_add">
                                            <div {if condition="in_array('1000'.$vo.id,$menu_id_arr)"}title="取消导航显示" class="iconfont e-jiahao2 e-jianhao"{else /}title="加入导航显示"  class="iconfont e-jiahao2"{/if} data-menu_id="1000{$vo.id}" data-name="{$vo.name}" data-param="{$vo.config.management.href|handle_weapp_url=###}" data-target="{$vo.config.management.target|default='workspace'}" ></div>
                                        </div>
                                    {else /}
                                        <div class="icon-link_add">
                                            <div {if condition="in_array('1000'.$vo.id,$menu_id_arr)"}title="取消导航显示" class="iconfont e-jiahao2 e-jianhao"{else /}title="加入导航显示"  class="iconfont e-jiahao2"{/if} data-menu_id="1000{$vo.id}" data-name="{$vo.name}" data-param="|sm|{$vo.code}|sc|{$vo.code}|sa|index" data-target="{$vo.config.management.target|default='workspace'}" ></div>
                                        </div>
                                    {/if}
                                {/notempty}
                            </div>
                            <div class="plug-text-versions">
                                <span>版本：{$vo.config.version|default='未知'}</span>
                                {assign name="weapp_upgrade_info" value="$weapp_upgrade[$vo['code']]" /}
                                {eq name="$weapp_upgrade_info['code']" value='2'}
                                <span>
                                    <textarea id="{$vo.code}_upgrade" class="none">{$weapp_upgrade_info['msg']['upgrade']|default=''}</textarea> 
                                    <textarea id="{$vo.code}_intro" class="none">{$weapp_upgrade_info['msg']['intro']|default=''}</textarea>
                                    <textarea id="{$vo.code}_notice" class="none">{$weapp_upgrade_info['msg']['notice']|default=''}</textarea>
                                    <a href="javascript:void(0);" class="a_upgrade red" data-version="{$vo.version}" data-code="{$vo.code}" data-status="{$vo.status|default='0'}" data-name="{$vo.name}" onclick="weapp_upgrade(this);">{$weapp_upgrade_info['msg']['tips']|default='[新版本更新]'}</a>
                                </span>
                                {/eq}
                            </div>  
                            <div class="plug-text-des">
                              {$vo.config.description|default='暂无描述~'}
                            </div>
                        </div>
                    </div>
                    <div class="plug-item-bottm">
                        {empty name="$vo.status"}
                            {empty name="$vo.is_buy"}
                                {eq name="'Weapp@install'|is_check_access" value="1"}
                                <a href="javascript:void(0);" onclick="install(this);" data-id="{$vo['id']}" class="btn blue">安装</a>
                                {/eq}
                                {eq name="'Weapp@del'|is_check_access" value="1"}
                                <a href="javascript:void(0);" data-url="{:url('Weapp/del')}" data-id="{$vo.id}" data-name="{$vo.name}" onClick="delfun(this);">删除</a>
                                {/eq}
                            {else /}
                                {eq name="'Weapp@install'|is_check_access" value="1"}
                                <a href="javascript:void(0);" onclick="remoteInstall('{$vo['code']}', '{$vo['min_version']}');">安装</a>
                                {/eq}
                                {eq name="'Weapp@del_remote'|is_check_access" value="1"}
                                <a href="javascript:void(0);" data-url="{:url('Weapp/del_remote')}" data-id="{$vo.id}" data-menu_id="1000{$vo.id}" data-name="{$vo.name}" onClick="del_remote(this);">删除</a>
                                {/eq}
                            {/empty}
                        {else /}
                            {eq name="'Weapp@execute'|is_check_access" value="1"}
                                {if condition="empty($vo['config']['management']['href'])"}
                                <a href="{:url('Weapp/execute',array('sm'=>$vo['code'],'sc'=>$vo['code'],'sa'=>'index'))}">管理</a>
                                {else /}
                                <a href="{$vo['config']['management']['href']}" target="{$vo['config']['management']['target']|default='_self'}">管理</a>
                                {/if}
                            {/eq}
                            {eq name="'Weapp@uninstall'|is_check_access" value="1"}
                                <a href="javascript:void(0);" onclick="uninstall(this);" data-id="{$vo['id']}" data-menu_id="1000{$vo.id}" data-name="{$vo.name}">卸载</a>
                            {/eq}
                        {/empty}

                        <div class="plug-status">
                            {if condition="$vo['status'] eq 1"}
                                <span style="cursor: pointer;" class="yes" {eq name="'Weapp@disable'|is_check_access" value="1"}onClick="changeTableVal('weapp','id','{$vo.id}','status',this);"{/eq} data-value="-1" data-weapp_code="{$vo.code}" data-yestext="<i class='fa fa-check-circle'></i>已启用" data-notext="<i class='fa fa-ban'></i>已禁用"><i class="fa fa-check-circle"></i>已启用</span>
                            {else /}
                                <span style="cursor: pointer;" class="no" {eq name="'Weapp@disable'|is_check_access" value="1"}onClick="changeTableVal('weapp','id','{$vo.id}','status',this);"{/eq} data-value="1" data-weapp_code="{$vo.code}" data-yestext="<i class='fa fa-check-circle'></i>已启用" data-notext="<i class='fa fa-ban'></i>已禁用"><i class="fa fa-ban"></i>已禁用</span>
                            {/if}
                            {eq name='$vo.code' value='Diyminipro'}
                            <script type="text/javascript">
                                $(function(){
                                    var diymimipro_status = "{$vo['status']}";
                                    if ('1' == diymimipro_status) {
                                        $('#Diyminipro_theme_index', window.parent.document).show();
                                    } else {
                                        $('#Diyminipro_theme_index', window.parent.document).hide();
                                    }
                                });
                            </script>
                            {/eq}
                        </div>
                    </div>
                </div>
                {/foreach}
            {/empty}
			<div class="flexigrid">
			<div class="footer-oper">
				<div class="fbuttonr">
				    <div class="pages">
				       {$page}
				    </div>
				</div>
			    <div style="clear:both"></div>
			</div>
			</div>
        </div>
		
    </div>
</div>
<form name="form2" id="form2" method="post" action="">
    <input type="hidden" name="id" value="" />
    <input type="hidden" name="code" value=""/>
    <input type="hidden" name="min_version" value=""/>
    <input type="hidden" name="thorough" value="1" />
</form>
<script>
    $(document).ready(function(){

        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });
    });

    function weapp_upgrade(obj)
    {
        var name = $(obj).attr('data-name');
        var status = $(obj).attr('data-status');
        if (0 == status) {
            layer.alert('请先安装该插件！', {
                title:false,//name,
                icon: 0
            });
            return false;
        }

        var code = $(obj).attr('data-code');
        var v = $("#"+code+"_upgrade").val();    
        var intro = $("#"+code+"_intro").val();   
        intro += '<style type="text/css">.layui-layer-content{height:270px!important;text-align:left!important;}</style>';
        var notice = $("#"+code+"_notice").val(); 
        v = notice + intro + '<br/>' + v;
        //询问框
        layer.confirm(v, {
            shade: layer_shade,
            area: ['580px','400px'],
            move: false,
            title: '新版本更新',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['升级','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function(){
            layer.closeAll();
            setTimeout(function(){
                upgrade(code); // 请求后台
            },200);
            
        }, function(index){  
            layer.close(index);
        });    
    }

    function upgrade(code){
        layer_loading('升级中');
        $.ajax({
            type : "GET",
            url  : "{:url('Weapp/OneKeyUpgrade')}",
            timeout : 360000, //超时时间设置，单位毫秒 设置了 1小时
            data : {code:code, _ajax:1},
            error: function(request) {
                layer.closeAll();
                layer.alert("升级失败！", {icon: 5, closeBtn: false, title:false}, function(){
                    window.location.reload();
                });
            },
            success: function(res) {
                if(1 == res.code){
                    $.ajax({
                        type : 'GET',
                        url : eyou_basefile+"?m=admin&c=Weapp&a=execute&sm="+code+"&sc="+code+"&sa=afterUpgrade&lang="+__lang__,
                        timeout : 360000, //超时时间设置，单位毫秒 设置了 1小时
                        data : {_ajax:1},
                        dataType : 'json',
                        success : function(res){
                            layer.closeAll();
                            layer.msg('已升级最新版本!', {time:1000}, function(){
                                window.location.reload();
                            });
                        },
                        error: function(e) {
                            layer.closeAll();
                            layer.msg('已升级最新版本!', {time:1000}, function(){
                                window.location.reload();
                            });
                        }
                    })
                }
                else{
                    layer.closeAll();
                    layer.alert(res.msg, {icon: 5, closeBtn: false, title:false}, function(){
                        window.location.reload();
                    });
                }
            }
        });
    }

    function install(obj)
    {
        var id = $(obj).attr('data-id');
        var form2 = $('#form2');
        form2.find('input[name=id]').val(id);
        var url = "{:url('Weapp/install')}";
        form2.attr('action', url);
        layer_loading('正在处理');
        form2.submit();
    }

    function uninstall(obj)
    {
        //询问框
        var confirm = layer.confirm('数据将不可恢复，是否卸载？', {
                shade: layer_shade,
                area: ['480px', '190px'],
                move: false,
                title: '提示',
                btnAlign:'r',
                closeBtn: 3,
                btn: ['确定', '取消'] ,//按钮
                success: function () {
                      $(".layui-layer-content").css('text-align', 'left');
                  }
            }, function(){
                layer.close(confirm);
                uninstall_true(obj);
            }, function(){
                layer.close(confirm);
            }
        );
        
        return false;
    }

    function uninstall_true(obj)
    {
        var id = $(obj).attr('data-id');

        layer_loading('正在处理');
        // 确定
        $.ajax({
            type : 'post',
            url : "{:url('Weapp/uninstall')}",
            data : {id:id, thorough:0, _ajax:1},
            dataType : 'json',
            success : function(res){
                layer.closeAll();
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        var menu_id = $(obj).attr('data-menu_id');
                        $(".Weapp_execute_" + menu_id, window.parent.document).remove();
                        if ('_parent' == res.data.install_target) {
                            top.window.location.reload();
                        } else {
                            window.location.reload();
                        }
                    });
                }else{
                    layer.alert(res.msg, {icon: 5, title:false});
                }
            },
            error: function(e) {
                layer.closeAll();
                // 处理插件行为app_end影响到的卸载问题
                if (e.responseText.indexOf("\\behavior\\admin\\") >= 0 && e.responseText.indexOf("not found") >= 0) {
                    layer.msg('卸载成功', {icon: 1, time: 1000}, function(){
                        window.location.reload();
                    });
                } else {
                    layer.alert(e.responseText, {icon: 5, title:false});
                }
            }
        });
    }

    function delfun(obj){
        var name = $(obj).attr('data-name');
        layer.confirm('确认删除？', {
            area: ['480px', '190px'],
            shade: layer_shade,
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定','取消'] ,//按钮
            success: function () {
                  $(".layui-layer-content").css('text-align', 'left');
              }
        }, function(){
            layer_loading('正在处理');
            // 确定
            $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {del_id:$(obj).attr('data-id'), _ajax:1},
                dataType : 'json',
                success : function(res){
                    layer.closeAll();
                    if(res.code == 1){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                            var menu_id = $(obj).attr('data-menu_id');
                            $(".Weapp_execute_" + menu_id, window.parent.document).remove();
                            window.location.reload();
                        });
                    }else{
                        layer.alert(res.msg, {icon: 5, title:false});  //alert(res);
                    }
                }
            })
        }, function(index){
            layer.close(index);
        });
        return false;
    }

    function del_remote(obj){
        var name = $(obj).attr('data-name');
        layer.confirm('确认移除？', {
            area: ['480px', '190px'],
            shade: layer_shade,
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定','取消'] ,//按钮
            success: function () {
                  $(".layui-layer-content").css('text-align', 'left');
              }
        }, function(){
            layer_loading('正在处理');
            // 确定
            $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {del_id:$(obj).attr('data-id'), _ajax:1},
                dataType : 'json',
                success : function(data){
                    layer.closeAll();
                    if(data.code == 1){
                        layer.msg(data.msg, {icon: 1});
                        window.location.reload();
                    }else{
                        layer.alert(data.msg, {icon: 5, title:false});  //alert(data);
                    }
                }
            })
        }, function(index){
            layer.close(index);
        });
        return false;
    }

    function jump() {
        location.reload()
    }

    function remoteInstall(code, min_version) {
        var form2 = $('#form2');
        form2.find('input[name=code]').val(code);
        form2.find('input[name=min_version]').val(min_version);
        var url = "{:url('Weapp/remoteInstall')}";
        form2.attr('action', url);
        layer_loading('远程安装');
        form2.submit();
    }
</script>

{include file="public/footer" /}